﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElingOA6_Admin_DSJCJ.Common;
using ElingOA6_Admin_DSJCJ.Models;
using DevExpress.Web.Mvc;
using Newtonsoft.Json;
using ElingOA6_Admin_DSJCJ.Areas.Admin.Models;
using DevExpress.Web.ASPxUploadControl;
using System.IO;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.Areas.Admin.Controllers
{
    /// <summary>
    /// 信息类别管理
    /// </summary>
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class DocumentClsController : AdminBaseController
    {
        //
        // GET: /Admin/DocumentCls/

        /// <summary>
        /// 信息类别逻辑类
        /// </summary>
        private BLL.DocCls docClsBLL = new BLL.DocCls();
        /// <summary>
        /// 专题专栏模版逻辑类
        /// </summary>
        private BLL.ClsTempl clsTemplBLL = new BLL.ClsTempl();
        /// <summary>
        /// 信息类别权限逻辑类
        /// </summary>
        private BLL.DocClsAuthority docClsAuthorityBLL = new BLL.DocClsAuthority();
        /// <summary>
        /// 信息逻辑类
        /// </summary>
        private BLL.Document documentBLL = new BLL.Document();
        /// <summary>
        /// 系统模板逻辑类
        /// </summary>
        private BLL.SysTemplate sysTemplateBLL = new BLL.SysTemplate();
        /// <summary>
        /// 系统参数逻辑类
        /// </summary>
        private BLL.SysParam sysParamBLL = new BLL.SysParam();
        /// <summary>
        /// 信息文档查看权限逻辑类
        /// </summary>
        private BLL.documentAuthority documentAuthorityBLL = new BLL.documentAuthority();
        /// <summary>
        /// 信息类别管理首页
        /// </summary>
        /// <param name="focusNodeName">焦点名</param>
        /// <returns>视图</returns>
        [AuthorityActionFilter("m_DocumentCls", Order = 1)]
        [LogPageActionFilter("信息类别管理", Order = 2)]
        public ActionResult Index(string focusNodeName = "")
        {
            ViewData["focusNodeName"] = focusNodeName;
            List<Model.DocCls> docClsList = docClsBLL.GetListByEntityNo(GlobalConstant.ENTITYNO);
            ViewData["isHaveTreeData"] = docClsList.Count == 0 ? false : true;
            //ViewData["currentYear"] = 2013;
            //ViewData["maxYear"] = 2014;
            //ViewData["minYear"] = 2013;
            return View();
        }
        /// <summary>
        /// 左边栏目列表树
        /// </summary>
        /// <param name="focusNodeName">焦点名</param>
        /// <param name="type">类型</param>
        /// <returns>视图</returns>
        public ActionResult DocumentClsTree(string focusNodeName = "", string type = "")
        {
            string docClsLeftTreeType = type;  //左边栏目树类型 空-栏目管理 TEMPLATE-模版管理

            ElingOA6_Admin_DSJCJ.Models.TreeModelList treeModelList = new TreeModelList();
            switch (docClsLeftTreeType)
            {
                case "TEMPLATE":
                    {
                        //TreeItemModel treeParentItemModel = new TreeItemModel(null)
                        //{
                        //    Id = Url.Action("TemplateList", "SysTemplate", new { clscd = "", type = "" }),
                        //    Name = "全局模板"
                        //};
                        List<Model.DocCls> docClsList = docClsBLL.GetListByEntityNo(GlobalConstant.ENTITYNO);
                        if (docClsList.Count > 0)
                        {
                            List<Model.DocCls> docClsFirstList = (from m in docClsList
                                                                  where m.FPreDocClsCd == ""
                                                                  select m).ToList();

                            foreach (Model.DocCls docClsModel in docClsFirstList)
                            {
                                List<Model.DocCls> tmpModelList = (from m in docClsList
                                                                   where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                                   select m).ToList();

                                TreeItemModel treeParentItemModel = new TreeItemModel(null)
                                {
                                    Id = Url.Action("TemplateList", "SysTemplate", new { clscd = docClsModel.FDocClsCd, type = docClsModel.FEditMode }),
                                    Name = docClsModel.FDocClsName
                                };
                                if (tmpModelList.Count > 0)
                                {
                                    GetChildDocClsList(tmpModelList, treeParentItemModel, docClsList, docClsLeftTreeType);
                                }
                                treeModelList.Add(treeParentItemModel);
                            }
                        }
                        break;
                    }
                case "PUB":
                    {
                        //信息发布树
                        string deptNo = OperateSession.get(GlobalConstant.PARAM_DEPTNO);
                        string empNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
                        List<Model.DocCls> docClsList = new List<Model.DocCls>();
                        DataTable authorityDT = docClsBLL.GetListByAuthority(GlobalConstant.ENTITYNO, empNo, deptNo, "PUB");
                        for (int i = 0; i < authorityDT.Rows.Count; i++)
                        {
                            DataRow dr = authorityDT.Rows[i];
                            Model.DocCls docClsModel = new Model.DocCls()
                            {
                                FDocClsCd = dr["Fdocclscd"].ToString(),
                                FPreDocClsCd = dr["fpredocclscd"].ToString(),
                                FDocClsProp = dr["fdocclsprop"].ToString(),
                                FDocClsName = dr["fdocclsname"].ToString(),
                                IsAuthority = dr["fisauthority"].ToString(),
                                FSeq = int.Parse(dr["FSeq"].ToString())
                            };
                            docClsList.Add(docClsModel);
                        }
                        if (docClsList.Count > 0)
                        {

                            TreeItemModel treeParentItemModel = new TreeItemModel(null)
                            {
                                Id = Url.Action("DocumentList", "DocumentPub"),
                                Name = "全部类别"
                            };

                            List<Model.DocCls> docClsFirstList = (from m in docClsList
                                                                  where m.FPreDocClsCd == ""
                                                                  select m).OrderBy(s=>s.FSeq).ToList();

                            foreach (Model.DocCls docClsModel in docClsFirstList)
                            {
                                List<Model.DocCls> tmpModelList = (from m in docClsList
                                                                   where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                                   select m).OrderBy(s => s.FSeq).ToList();

                                TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                                {
                                    Id = Url.Action("DocumentList", "DocumentPub", new { docClsCd = docClsModel.FDocClsCd }),
                                    Name = docClsModel.FDocClsName
                                };
                                if (tmpModelList.Count > 0)
                                {
                                    GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                                }

                            }
                            treeModelList.Add(treeParentItemModel);
                        }
                        break;
                    }
                case "REF":
                    {
                        //信息引用管理
                        //信息类别树(与信息发布权限相同)
                        string deptNo = OperateSession.get(GlobalConstant.PARAM_DEPTNO);
                        string empNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
                        List<Model.DocCls> docClsList = new List<Model.DocCls>();
                        DataTable authorityDT = docClsBLL.GetListByAuthority(GlobalConstant.ENTITYNO, empNo, deptNo, "PUB");
                        for (int i = 0; i < authorityDT.Rows.Count; i++)
                        {
                            DataRow dr = authorityDT.Rows[i];
                            Model.DocCls docClsModel = new Model.DocCls()
                            {
                                FDocClsCd = dr["Fdocclscd"].ToString(),
                                FPreDocClsCd = dr["fpredocclscd"].ToString(),
                                FDocClsProp = dr["fdocclsprop"].ToString(),
                                FDocClsName = dr["fdocclsname"].ToString(),
                                IsAuthority = dr["fisauthority"].ToString(),
                                FSeq = int.Parse(dr["FSeq"].ToString())
                            };
                            docClsList.Add(docClsModel);
                        }
                        if (docClsList.Count > 0)
                        {

                            TreeItemModel treeParentItemModel = new TreeItemModel(null)
                            {
                                Id = Url.Action("DocumentList", "DocRefImp"),
                                Name = "全部类别"
                            };

                            List<Model.DocCls> docClsFirstList = (from m in docClsList
                                                                  where m.FPreDocClsCd == ""
                                                                  select m).OrderBy(s => s.FSeq).ToList();

                            foreach (Model.DocCls docClsModel in docClsFirstList)
                            {
                                List<Model.DocCls> tmpModelList = (from m in docClsList
                                                                   where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                                   select m).OrderBy(s => s.FSeq).ToList();

                                TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                                {
                                    Id = Url.Action("DocumentList", "DocRefImp", new { docClsCd = docClsModel.FDocClsCd }),
                                    Name = docClsModel.FDocClsName
                                };
                                if (tmpModelList.Count > 0)
                                {
                                    GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                                }

                            }
                            treeModelList.Add(treeParentItemModel);
                        }
                        break;
                    }
                case "MANAGE":
                    {
                        //信息维护树
                        string deptNo = OperateSession.get(GlobalConstant.PARAM_DEPTNO);
                        string empNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
                        List<Model.DocCls> docClsList = new List<Model.DocCls>();
                        DataTable authorityDT = docClsBLL.GetListByAuthority(GlobalConstant.ENTITYNO, empNo, deptNo, "MANAGE");
                        for (int i = 0; i < authorityDT.Rows.Count; i++)
                        {
                            DataRow dr = authorityDT.Rows[i];
                            Model.DocCls docClsModel = new Model.DocCls()
                            {
                                FDocClsCd = dr["Fdocclscd"].ToString(),
                                FPreDocClsCd = dr["fpredocclscd"].ToString(),
                                FDocClsProp = dr["fdocclsprop"].ToString(),
                                FDocClsName = dr["fdocclsname"].ToString(),
                                IsAuthority = dr["fisauthority"].ToString(),
                                FSeq = int.Parse(dr["FSeq"].ToString())
                            };
                            docClsList.Add(docClsModel);
                        }
                        if (docClsList.Count > 0)
                        {

                            TreeItemModel treeParentItemModel = new TreeItemModel(null)
                            {
                                Id = Url.Action("DocumentList", "DocumentManage"),
                                Name = "全部类别"
                            };

                            List<Model.DocCls> docClsFirstList = (from m in docClsList
                                                                  where m.FPreDocClsCd == ""
                                                                  select m).OrderBy(s => s.FSeq).ToList();

                            foreach (Model.DocCls docClsModel in docClsFirstList)
                            {
                                List<Model.DocCls> tmpModelList = (from m in docClsList
                                                                   where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                                   select m).OrderBy(s=>s.FSeq).ToList();

                                TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                                {
                                    Id = Url.Action("DocumentList", "DocumentManage", new { docClsCd = docClsModel.FDocClsCd }),
                                    Name = docClsModel.FDocClsName
                                };
                                if (tmpModelList.Count > 0)
                                {
                                    GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                                }
                                
                            }
                            treeModelList.Add(treeParentItemModel);
                        }
                        break;
                    }
                case "AUDIT":
                    {
                        //信息审核树
                        string deptNo = OperateSession.get(GlobalConstant.PARAM_DEPTNO);
                        string empNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
                        List<Model.DocCls> docClsList = new List<Model.DocCls>();
                        DataTable authorityDT = docClsBLL.GetListByAuthority(GlobalConstant.ENTITYNO, empNo, deptNo, "AUDIT");
                        for (int i = 0; i < authorityDT.Rows.Count; i++)
                        {
                            DataRow dr = authorityDT.Rows[i];
                            Model.DocCls docClsModel = new Model.DocCls()
                            {
                                FDocClsCd = dr["Fdocclscd"].ToString(),
                                FPreDocClsCd = dr["fpredocclscd"].ToString(),
                                FDocClsProp = dr["fdocclsprop"].ToString(),
                                FDocClsName = dr["fdocclsname"].ToString(),
                                IsAuthority = dr["fisauthority"].ToString(),
                                FSeq = int.Parse(dr["FSeq"].ToString())
                            };
                            docClsList.Add(docClsModel);
                        }
                        if (docClsList.Count > 0)
                        {

                            TreeItemModel treeParentItemModel = new TreeItemModel(null)
                            {
                                Id = Url.Action("DocumentList", "DocumentAudit"),
                                Name = "全部类别"
                            };

                            List<Model.DocCls> docClsFirstList = (from m in docClsList
                                                                  where m.FPreDocClsCd == ""
                                                                  select m).OrderBy(s=>s.FSeq).ToList();

                            foreach (Model.DocCls docClsModel in docClsFirstList)
                            {
                                List<Model.DocCls> tmpModelList = (from m in docClsList
                                                                   where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                                   select m).OrderBy(s => s.FSeq).ToList();

                                TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                                {
                                    Id = Url.Action("DocumentList", "DocumentAudit", new { docClsCd = docClsModel.FDocClsCd }),
                                    Name = docClsModel.FDocClsName
                                };
                                if (tmpModelList.Count > 0)
                                {
                                    GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                                }
                                
                            }
                            treeModelList.Add(treeParentItemModel);
                        }
                        break;
                    }
                case "JCMS":
                    {
                        //JCMS推送树
                        List<Model.DocCls> docClsList = new List<Model.DocCls>();
                        DataTable authorityDT = docClsBLL.GetListIsJcmsByEntityNo(GlobalConstant.ENTITYNO);
                        for (int i = 0; i < authorityDT.Rows.Count; i++)
                        {
                            DataRow dr = authorityDT.Rows[i];
                            Model.DocCls docClsModel = new Model.DocCls()
                            {
                                FDocClsCd = dr["Fdocclscd"].ToString(),
                                FPreDocClsCd = dr["fpredocclscd"].ToString(),
                                FDocClsName = dr["fdocclsname"].ToString(),
                                FSeq = int.Parse(dr["FSeq"].ToString())
                            };
                            docClsList.Add(docClsModel);
                        }
                        if (docClsList.Count > 0)
                        {

                            TreeItemModel treeParentItemModel = new TreeItemModel(null)
                            {
                                Id = Url.Action("DocumentList", "JcmsPushTo"),
                                Name = "全部类别"
                            };

                            List<Model.DocCls> docClsFirstList = (from m in docClsList
                                                                  where m.FPreDocClsCd == ""
                                                                  select m).OrderBy(s => s.FSeq).ToList();

                            foreach (Model.DocCls docClsModel in docClsFirstList)
                            {
                                List<Model.DocCls> tmpModelList = (from m in docClsList
                                                                   where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                                   select m).OrderBy(s => s.FSeq).ToList();

                                TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                                {
                                    Id = Url.Action("DocumentList", "JcmsPushTo", new { docClsCd = docClsModel.FDocClsCd }),
                                    Name = docClsModel.FDocClsName
                                };
                                if (tmpModelList.Count > 0)
                                {
                                    GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                                }

                            }
                            treeModelList.Add(treeParentItemModel);
                        }
                        break;
                    }
                default:
                    {
                        List<Model.DocCls> docClsList = docClsBLL.GetListAllByEntityNo(GlobalConstant.ENTITYNO);
                        if (docClsList.Count > 0)
                        {
                            List<Model.DocCls> docClsFirstList = (from m in docClsList
                                                                  where m.FPreDocClsCd == ""
                                                                  select m).OrderBy(s => s.FSeq).ToList();

                            foreach (Model.DocCls docClsModel in docClsFirstList)
                            {
                                List<Model.DocCls> tmpModelList = (from m in docClsList
                                                                   where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                                   select m).OrderBy(s => s.FSeq).ToList();

                                TreeItemModel treeParentItemModel = new TreeItemModel(null)
                                {
                                    Id = Url.Action("DocumentClsEdit", "DocumentCls", new { docClsCd = docClsModel.FDocClsCd, actionOP = BaseStruct.ActionOperationStruct.EDIT }),
                                    Name = docClsModel.FDocClsName
                                };
                                treeParentItemModel.Id = treeParentItemModel.Id.Replace("&", "|");
                                if (tmpModelList.Count > 0)
                                {
                                    GetChildDocClsList(tmpModelList, treeParentItemModel, docClsList, docClsLeftTreeType);
                                }
                                treeModelList.Add(treeParentItemModel);
                            }
                        }
                        break;
                    }
            }


            ViewData["focusNodeName"] = focusNodeName;
            return PartialView(treeModelList);
        }
        /// <summary>
        /// 递归获取树形菜单
        /// </summary>
        /// <param name="docClsChildList">下级栏目类别列表</param>
        /// <param name="treeParentItemModel">上级栏目对象</param>
        /// <param name="docClsList">所有栏目列表</param>
        /// <param name="docClsLeftTreeType">栏目树类型</param>
        public void GetChildDocClsList(List<Model.DocCls> docClsChildList, TreeItemModel treeParentItemModel, List<Model.DocCls> docClsList, string docClsLeftTreeType)
        {

            foreach (Model.DocCls docClsModel in docClsChildList)
            {
                List<Model.DocCls> tmpModelList = (from m in docClsList
                                                   where m.FPreDocClsCd == docClsModel.FDocClsCd
                                                   select m).OrderBy(s => s.FSeq).ToList();

                switch (docClsLeftTreeType)
                {
                    case "TEMPLATE":
                        {
                            TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                            {
                                Id = Url.Action("TemplateList", "SysTemplate", new { clscd = docClsModel.FDocClsCd, type = docClsModel.FEditMode }),
                                Name = docClsModel.FDocClsName
                            };
                            if (tmpModelList.Count > 0)
                            {
                                GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                            }
                            break;
                        }
                    case "PUB":
                        {
                            //信息发布
                            TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                            {
                                Id = Url.Action("DocumentList", "DocumentPub", new { docClsCd = docClsModel.FDocClsCd }),
                                Name = docClsModel.FDocClsName
                            };
                            if (tmpModelList.Count > 0)
                            {
                                GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                            }
                            break;
                        }
                    case "REF":
                        {
                            //信息引用
                            TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                            {
                                Id = Url.Action("DocumentList", "DocRefImp", new { docClsCd = docClsModel.FDocClsCd }),
                                Name = docClsModel.FDocClsName
                            };
                            if (tmpModelList.Count > 0)
                            {
                                GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                            }
                            break;
                        }
                    case "MANAGE":
                        {
                            //信息发布
                            TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                            {
                                Id = Url.Action("DocumentList", "DocumentManage", new { docClsCd = docClsModel.FDocClsCd }),
                                Name = docClsModel.FDocClsName
                            };
                            if (tmpModelList.Count > 0)
                            {
                                GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                            }
                            break;
                        }
                    case "AUDIT":
                        {
                            //信息审核
                            TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                            {
                                Id = Url.Action("DocumentList", "DocumentAudit", new { docClsCd = docClsModel.FDocClsCd }),
                                Name = docClsModel.FDocClsName
                            };
                            if (tmpModelList.Count > 0)
                            {
                                GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                            }
                            break;
                        }
                    case "JCMS":
                        {
                            //JCMS推送树
                            TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                            {
                                Id = Url.Action("DocumentList", "JcmsPushTo", new { docClsCd = docClsModel.FDocClsCd }),
                                Name = docClsModel.FDocClsName
                            };
                            if (tmpModelList.Count > 0)
                            {
                                GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                            }
                            break;
                        }
                    default:
                        {
                            TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                            {
                                Id = Url.Action("DocumentClsEdit", "DocumentCls", new { docClsCd = docClsModel.FDocClsCd, actionOP = BaseStruct.ActionOperationStruct.EDIT }),
                                Name = docClsModel.FDocClsName
                            };
                            treeChildItemModel.Id = treeChildItemModel.Id.Replace("&", "|");
                            if (tmpModelList.Count > 0)
                            {
                                GetChildDocClsList(tmpModelList, treeChildItemModel, docClsList, docClsLeftTreeType);
                            }

                            break;
                        }
                }
            }
        }
        /// <summary>
        /// 信息类别编辑(增加)
        /// </summary>
        /// <param name="docClsCd">栏目编号</param>
        /// <param name="actionOperation">操作类型</param>
        /// <returns>视图</returns>
        public ActionResult DocumentClsEdit(string docClsCd = "", string actionOP = BaseStruct.ActionOperationStruct.ADD_NEXT, int pageIndex = 1)
        {
            return DocumentClsEdit(docClsCd, actionOP, "", null, pageIndex);
        }
        /// <summary>
        /// 信息类别编辑(增加)
        /// </summary>
        /// <param name="docClsCd">栏目编号</param>
        /// <param name="actionOP">操作类型</param>
        /// <param name="jsAlert">错误信息</param>
        /// <param name="docClsModel">信息类别实体类</param>
        /// <returns>
        /// 视图
        /// </returns>
        private ActionResult DocumentClsEdit(string docClsCd, string actionOP, string jsAlert, Model.DocCls docClsModel, int pageIndex = 1)
        {
            ViewData["pageIndex"] = pageIndex;
            string entityNo = GlobalConstant.ENTITYNO;
            ViewData["isChild"] = docClsBLL.GetChildeCount(docClsCd, entityNo);
            List<SelectListItem> items = new List<SelectListItem>();
            items.Add(new SelectListItem() { Text = "多信息", Value = BaseStruct.DocClsTypeStruct.MUTI });
            items.Add(new SelectListItem() { Text = "单信息", Value = BaseStruct.DocClsTypeStruct.SINGLE });
            items.Add(new SelectListItem() { Text = "无信息", Value = BaseStruct.DocClsTypeStruct.EMPTY });
            ViewData["docClsPropSelection"] = items;
            List<SelectListItem> defaultShowValueSelectionItems = new List<SelectListItem>();
            defaultShowValueSelectionItems.Add(new SelectListItem() { Text = "显示", Value = "Y" });
            defaultShowValueSelectionItems.Add(new SelectListItem() { Text = "不显示", Value = "N" });
            ViewData["defaultShowValueSelection"] = defaultShowValueSelectionItems;

            //级别
            items = new List<SelectListItem>();
            items.Add(new SelectListItem() { Text = "正级", Value = BaseStruct.ClsAuthorityPropStruct.ZHENGJI });
            items.Add(new SelectListItem() { Text = "副级", Value = BaseStruct.ClsAuthorityPropStruct.FUJI });
            items.Add(new SelectListItem() { Text = "正副级", Value = BaseStruct.ClsAuthorityPropStruct.ZHENGFUJI });
            items.Add(new SelectListItem() { Text = "任何人", Value = BaseStruct.ClsAuthorityPropStruct.RENHEREN });
            ViewData["clsAuthorityPropSelection"] = items;


            items = new List<SelectListItem>();
            items.Add(new SelectListItem() { Text = "图片", Value = BaseStruct.WaterTypeStruct.IMG });
            items.Add(new SelectListItem() { Text = "文本", Value = BaseStruct.DocClsTypeStruct.SINGLE });
            ViewData["waterTypePropSelection"] = items;

            List<Model.DocClsAuthority> docClsAuthorityList = new List<Model.DocClsAuthority>();
            if (docClsModel == null)
            {
                Model.DocCls oldDcClsModel = docClsBLL.GetModel(entityNo, docClsCd);

                switch (actionOP)
                {
                    case BaseStruct.ActionOperationStruct.ADD_SAME:
                    case BaseStruct.ActionOperationStruct.ADD_NEXT:
                        {
                            docClsModel = new Model.DocCls();
                            if (actionOP == BaseStruct.ActionOperationStruct.ADD_SAME)
                            {
                                docClsModel.FPreDocClsCd = oldDcClsModel != null ? oldDcClsModel.FPreDocClsCd : null;
                            }
                            else
                            {
                                docClsModel.FPreDocClsCd = oldDcClsModel != null ? oldDcClsModel.FDocClsCd : null;
                            }
                            docClsModel.FDocClsProp = items[0].Value;
                            docClsModel.FDefaultEditMode = "H";
                            docClsModel.FEditMode = "H";
                            docClsModel.FLookAuthorityMode = "A";
                            break;
                        }

                    case BaseStruct.ActionOperationStruct.EDIT:
                        {
                            if (oldDcClsModel != null)
                            {
                                docClsModel = oldDcClsModel;
                                //读取权限
                                docClsAuthorityList = docClsAuthorityBLL.GetListByClsCd(entityNo, docClsModel.FDocClsCd);
                            }
                            int documentCount = documentBLL.GetDocCountByDocClsCd(entityNo, docClsCd);
                            ViewData["documentCount"] = documentCount;
                            break;
                        }
                }
            }
            if (docClsModel != null)
            {
                //专题专栏模版选择
                List<Model.ClsTempl> clsTemplList = clsTemplBLL.GetListByEntityNo(entityNo);
                List<Model.ClsTempl> tmpClsTemplList = new List<Model.ClsTempl>();
                tmpClsTemplList.Add(new Model.ClsTempl() { FClsTemplID = decimal.Parse(GlobalConstant.COMBO_NOCHOOSE_VALUE), FTemplName = GlobalConstant.COMBO_NOCHOOSE_TEXT });
                foreach (Model.ClsTempl clsTemplModel in clsTemplList)
                {
                    tmpClsTemplList.Add(clsTemplModel);

                }
                if (!docClsModel.FClsTemplID.HasValue)
                {
                    docClsModel.FClsTemplID = -1;
                }
                ViewData["clsTemplList"] = tmpClsTemplList;
            }
            else
            {
                return null;
            }
            //判断是否显示JCMS相关内容
            ViewData["useJCMSInterface"] = "N";
            if (sysParamBLL.GetParamValue("OA_USE_JCMS_INTERFACE", entityNo) == "Y")
            {
                ViewData["useJCMSInterface"] = "Y";
            }

            ViewData["jsAlert"] = jsAlert;
            //隐藏字段
            ViewData["hdMethod"] = actionOP.ToString();
            ElingOA6_Admin_DSJCJ.Areas.Admin.Models.DocumentClsViewModel docClsViewModel =
                new Models.DocumentClsViewModel(docClsModel, docClsAuthorityList);

            return View("DocumentClsEdit", docClsViewModel);
        }
        /// <summary>
        /// 获取专题专栏模板的图片
        /// </summary>
        /// <param name="templID"></param>
        /// <returns></returns>
        public string GetTemplPathAndPicPath(string templID)
        {
            string returnValue = string.Empty;
            string entityNo = GlobalConstant.ENTITYNO;
            decimal templId = 0;
            string templIdstr = Fetch.estimateString(Request.Form["templID"], CheckGetEnum.Safety);
            if (decimal.TryParse(templIdstr, out templId))
            {
                Model.ClsTempl clsTemplModel = clsTemplBLL.GetModel(templId, entityNo);
                if (clsTemplModel != null)
                {
                    returnValue = JsonConvert.SerializeObject(clsTemplModel);
                }
            }
            return returnValue;

        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="docClsModel">信息类别实体类</param>
        [HttpPost]
        public ActionResult Save(Model.DocCls docClsModel)
        {
            bool isSuccess = true;
            string errorMessage = "";
            ActionResult actionResult = null;
            string entityNo = GlobalConstant.ENTITYNO;
            Model.DocCls newDocClsModel = new Model.DocCls();
            //基本信息
            newDocClsModel.FEntityNo = entityNo;
            newDocClsModel.FDocClsCd = Fetch.Post("FDocClsCd");
            newDocClsModel.FPreDocClsCd = Fetch.Post("FPreDocClsCd");
            newDocClsModel.FDocClsName = docClsModel.FDocClsName;
            newDocClsModel.FDocClsProp = docClsModel.FDocClsProp;
            newDocClsModel.FEditMode = docClsModel.FEditMode;
            newDocClsModel.FDefaultEditMode = Fetch.Post("FDefaultEditMode_VI");
            newDocClsModel.FIsUse = docClsModel.FIsUse;
            newDocClsModel.FUseSubTitle = docClsModel.FUseSubTitle;
            newDocClsModel.FIsHomePageShowLimit = Fetch.Post("FIsHomePageShowLimit") == "C" ? "Y" : "N";
            newDocClsModel.FHomePageShowDays = docClsModel.FHomePageShowDays;
            newDocClsModel.FIsShowHomePageCtrl = Fetch.Post("FIsShowHomePageCtrl") == "C" ? "Y" : "N";
            newDocClsModel.FDefaultShowValue = Fetch.Post("FDefaultShowValue_VI");
            newDocClsModel.FIsCtrlLookAuthority = Fetch.Post("FIsCtrlLookAuthority") == "C" ? "Y" : "N";
            newDocClsModel.FLookAuthorityMode = docClsModel.FLookAuthorityMode == null ? "A" : docClsModel.FLookAuthorityMode;
            newDocClsModel.FIsPublicTitle = Fetch.Post("FIsPublicTitle") == "C" ? "Y" : "N";
            newDocClsModel.FIsNeedAudit = Fetch.Post("FIsNeedAudit") == "C" ? "Y" : "N";
            newDocClsModel.FIsReferenceNo = Fetch.Post("FIsReferenceNo") == "C" ? "Y" : "N";
            newDocClsModel.FIsNotice = Fetch.Post("FIsNotice") == "C" ? "Y" : "N";
            newDocClsModel.FIsRecObject = Fetch.Post("FIsRecObject") == "C" ? "Y" : "N";
            newDocClsModel.FIsImport = Fetch.Post("FIsImport") == "C" ? "Y" : "N";
            newDocClsModel.FIsExamine = Fetch.Post("FIsExamine") == "C" ? "Y" : "N";
            newDocClsModel.FIsManuscript = Fetch.Post("FIsManuscript") == "C" ? "Y" : "N";
            newDocClsModel.FIsPicNews = Fetch.Post("FIsPicNews") == "C" ? 1 : 0;
            newDocClsModel.FIsSpecialTopic = Fetch.Post("FIsSpecialTopic") == "C" ? "Y" : "N";
            newDocClsModel.FIsVote = Fetch.Post("FIsVote") == "C" ? "Y" : "N";
            newDocClsModel.FIsPubJCMS = Fetch.Post("FIsPubJCMS") == "C" ? "Y" : "N";
            if (newDocClsModel.FIsPubJCMS == "Y")
            {
                newDocClsModel.FJCMSColID = docClsModel.FJCMSColID;
            }
            //数据逻辑验证
            if (newDocClsModel.FDocClsCd == "")
            {
                errorMessage = "信息类别编号不能为空";
                isSuccess = false;
            }

            if (isSuccess)
            {
                if (newDocClsModel.FDocClsName == "")
                {
                    errorMessage = "信息类别名称不能为空";
                    isSuccess = false;
                }
            }

            //图片新闻类
            if (newDocClsModel.FIsPicNews == 1)
            {
                newDocClsModel.FPicHeight = docClsModel.FPicHeight;
                newDocClsModel.FPicWidth = docClsModel.FPicWidth;
                newDocClsModel.FIsPicWaterMark = docClsModel.FIsPicWaterMark;
                if (newDocClsModel.FIsPicWaterMark == 1)
                {
                    //加水印
                    newDocClsModel.FWaterMarkCls = docClsModel.FWaterMarkCls;
                    newDocClsModel.FWaterMarkPos = Fetch.Post("hidWaterMarkPos");
                    newDocClsModel.FLeftRightMargin = docClsModel.FLeftRightMargin;
                    newDocClsModel.FTopBottomMargin = docClsModel.FTopBottomMargin;
                }
            }
            //专题专栏
            if (newDocClsModel.FIsSpecialTopic == "Y")
            {
                newDocClsModel.FClsTemplID = docClsModel.FClsTemplID;
                newDocClsModel.FDocClsHomepage = docClsModel.FDocClsHomepage;

            }
            //相关权限
            List<Model.DocClsAuthority> docClsAuthorityList = new List<Model.DocClsAuthority>();

            //发布权限
            GenerateClsAuthorityList("Pub", "PUB", entityNo, ref docClsAuthorityList);
            //维护权限
            GenerateClsAuthorityList("Manage", "MANAGE", entityNo, ref docClsAuthorityList);
            if (newDocClsModel.FIsNeedAudit == "Y")
            {
                //审核权限
                GenerateClsAuthorityList("Audit", "AUDIT", entityNo, ref docClsAuthorityList);
            }
            if (newDocClsModel.FIsCtrlLookAuthority == "Y")
            {
                //查看权限
                GenerateClsAuthorityList("Look", "LOOK", entityNo, ref docClsAuthorityList);
            }
            switch (Fetch.Post("hdMethod"))
            {
                case BaseStruct.ActionOperationStruct.EDIT:
                    {
                        //修改
                        try
                        {
                            if (isSuccess)
                            {
                                docClsBLL.UpdateDocClsandDocClsAuthority(newDocClsModel, docClsAuthorityList);
                                if (newDocClsModel.FIsSpecialTopic == "Y")
                                {
                                    LogoAndTopPicUpload(newDocClsModel.FDocClsCd, docClsModel, ref errorMessage);
                                }
                                else
                                {
                                    //删除原来的图片logo图片
                                    docClsBLL.EditDocClsLogoImg(null, null, null, entityNo, newDocClsModel.FDocClsCd);
                                    if (!string.IsNullOrEmpty(docClsModel.FLogoNewFileName))
                                    {
                                        GenerateUtil.DeleteFile(Url.Content("~" + docClsModel.FLogoNewFileName));
                                    }
                                    //删除原来的图片(顶部图片)
                                    docClsBLL.EditTopPicPath(null, entityNo, newDocClsModel.FDocClsCd);
                                    if (!string.IsNullOrEmpty(docClsModel.FTemplTopPicPath))
                                    {
                                        GenerateUtil.DeleteFile(Url.Content("~" + docClsModel.FTemplTopPicPath));
                                    }
                                }
                                ViewData["RedirectURL"] = Url.Action("DocumentClsEdit", "DocumentCls", new
                                {
                                    docClsCd = newDocClsModel.FDocClsCd,
                                    actionOP = BaseStruct.ActionOperationStruct.EDIT,
                                    jsAlert = "",
                                    docClsModel = newDocClsModel
                                });
                                ViewData["methodFromType"] = Fetch.Post("hdMethod");
                                ViewData["nodeText"] = newDocClsModel.FDocClsName;
                                actionResult = View("SuccessMessageByTree");

                            }

                        }
                        catch (Exception ee)
                        {
                            errorMessage = ee.Message;
                        }
                        if (actionResult == null)
                        {
                            actionResult = DocumentClsEdit(docClsModel.FDocClsCd, Fetch.Post("hdMethod"), errorMessage, docClsModel);
                        }
                        break;
                    }
                case BaseStruct.ActionOperationStruct.ADD_SAME:
                case BaseStruct.ActionOperationStruct.ADD_NEXT:
                    {
                        //增加
                        try
                        {
                            //判断编号是否存在
                            if (docClsBLL.Exists(entityNo, newDocClsModel.FDocClsCd))
                            {
                                errorMessage = "信息类别名称已经存在";
                                isSuccess = false;
                            }
                            if (isSuccess)
                            {
                                docClsBLL.AddDocClsAndDocClsAuthority(newDocClsModel, docClsAuthorityList);
                                if (newDocClsModel.FIsSpecialTopic == "Y")
                                {
                                    LogoAndTopPicUpload(newDocClsModel.FDocClsCd, docClsModel, ref errorMessage);
                                }
                                else
                                {
                                    //删除原来的图片logo图片
                                    docClsBLL.EditDocClsLogoImg(null, null, null, entityNo, newDocClsModel.FDocClsCd);
                                    if (!string.IsNullOrEmpty(docClsModel.FLogoNewFileName))
                                    {
                                        GenerateUtil.DeleteFile(Url.Content("~" + docClsModel.FLogoNewFileName));
                                    }
                                    //删除原来的图片(顶部图片)
                                    docClsBLL.EditTopPicPath(null, entityNo, newDocClsModel.FDocClsCd);
                                    if (!string.IsNullOrEmpty(docClsModel.FTemplTopPicPath))
                                    {
                                        GenerateUtil.DeleteFile(Url.Content("~" + docClsModel.FTemplTopPicPath));
                                    }
                                }
                                //ViewData["RedirectURL"] = Url.Action("DocumentClsEdit", "DocumentCls", new
                                //{
                                //    docClsCd = newDocClsModel.FDocClsCd,
                                //    actionOP = Fetch.Post("hdMethod"),
                                //    jsAlert = "",
                                //    docClsModel = newDocClsModel
                                //});
                                ViewData["methodFromType"] = Fetch.Post("hdMethod");
                                //ViewData["focusKey"] = DevExpressHelper.GetUrl(new { Controller = "DocumentCls", Action = "DocumentClsEdit" }) + "|" + newDocClsModel.FDocClsCd;//焦点定位的节点ID
                                //TreeItemModel treeChildItemModel = new TreeItemModel(treeParentItemModel)
                                //{
                                //    Id = Url.Action("DocumentClsEdit", "DocumentCls", new { docClsCd = docClsModel.FDocClsCd, actionOP = BaseStruct.ActionOperationStruct.EDIT }),
                                //    Name = docClsModel.FDocClsName
                                //};

                                ViewData["focusKey"] = Url.Action("DocumentClsEdit", "DocumentCls", new { docClsCd = docClsModel.FDocClsCd, actionOP = BaseStruct.ActionOperationStruct.EDIT });
                                ViewData["focusKey"] = ViewData["focusKey"].ToString().Replace("&", "|");
                                actionResult = View("SuccessMessageByTree");

                            }

                        }
                        catch (Exception ee)
                        {
                            errorMessage = ee.Message;
                        }
                        if (actionResult == null)
                        {
                            actionResult = DocumentClsEdit(docClsModel.FDocClsCd, Fetch.Post("hdMethod"), errorMessage, docClsModel);
                        }
                        break;
                    }
            }
            return actionResult;

        }
        /// <summary>
        /// 专题专栏相关图片上传
        /// </summary>
        /// <param name="docClsCd"></param>
        private void LogoAndTopPicUpload(string docClsCd, Model.DocCls docClsModel, ref string errorMessage)
        {
            string entityNo = GlobalConstant.ENTITYNO;
            //logo图片
            UploadedFile[] fileList = UploadControlExtension.GetUploadedFiles("logoUpload");
            if (fileList.Count() > 0)
            {
                try
                {
                    UploadedFile upload = fileList[0];
                    if (upload.FileBytes.Length > 0)
                    {
                        string imageFileName = Common.GenerateUtil.UploadImage(upload, Url.Content("~/Publish/" + entityNo + "/DocClsLOGO"));
                        switch (imageFileName)
                        {
                            case "1":
                                {
                                    errorMessage = "上传文件内容为空";
                                    break;
                                }
                            case "2":
                                {
                                    errorMessage = "上传类型不是图片";
                                    break;
                                }
                            case "3":
                                {
                                    errorMessage = "请上传图片类型";
                                    break;
                                }
                            case "4":
                                {
                                    errorMessage = "上传文件不能大于10M";
                                    break;
                                }
                            case "5":
                                {
                                    errorMessage = "上传文件已经存在";
                                    break;
                                }
                        }
                        if (errorMessage == "")
                        {
                            string imageurl = Url.Content("~/Publish/" + entityNo + "/DocClsLOGO/" + imageFileName);
                            string oldImgName = Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                            //获取图片二进制格式
                            byte[] buffer = upload.FileBytes;
                            try
                            {
                                docClsBLL.EditDocClsLogoImg(imageurl, oldImgName, buffer, entityNo, docClsCd);
                                //删除原来的图片(logo)
                                if (!string.IsNullOrEmpty(docClsModel.FLogoNewFileName))
                                {
                                    GenerateUtil.DeleteFile(Url.Content("~" + docClsModel.FLogoNewFileName));
                                }

                            }
                            catch (Exception ee)
                            {
                                errorMessage = "专题专栏图片更新数据库失败!" + ee.Message;
                            }

                        }
                    }
                }
                catch (Exception ee)
                {
                    errorMessage = "栏目logo图片上传出错" + ee.Message;
                }

            }
            if (errorMessage != "")
            {
                return;
            }
            //专题栏目栏目顶部图片
            fileList = UploadControlExtension.GetUploadedFiles("templTopPicPathUpload");
            if (fileList.Count() > 0)
            {
                try
                {
                    UploadedFile upload = fileList[0];
                    if (upload.FileBytes.Length > 0)
                    {
                        string imageFileName = Common.GenerateUtil.UploadImage(fileList[0], Url.Content("~/Publish/" + entityNo + "/DocClsLOGO"));
                        switch (imageFileName)
                        {
                            case "1":
                                {
                                    errorMessage = "上传文件内容为空";
                                    break;
                                }
                            case "2":
                                {
                                    errorMessage = "上传文件内容为空";
                                    break;
                                }
                            case "3":
                                {
                                    errorMessage = "请上传图片类型";
                                    break;
                                }
                            case "4":
                                {
                                    errorMessage = "上传文件不能大于10M";
                                    break;
                                }
                            case "5":
                                {
                                    errorMessage = "上传文件已经存在";
                                    break;
                                }
                        }
                        if (errorMessage == "")
                        {
                            string imageurl = Url.Content("~/Publish/" + entityNo + "/DocClsLOGO/" + imageFileName);
                            string oldImgName = Path.GetFileNameWithoutExtension(upload.FileName) + Path.GetExtension(upload.FileName).ToLower();
                            //获取图片二进制格式
                            byte[] buffer = upload.FileBytes;
                            try
                            {
                                docClsBLL.EditTopPicPath(imageurl, entityNo, docClsCd);
                                //删除原来的图片(顶部图片)
                                if (!string.IsNullOrEmpty(docClsModel.FTemplTopPicPath))
                                {
                                    GenerateUtil.DeleteFile(Url.Content("~" + docClsModel.FTemplTopPicPath));
                                }
                            }
                            catch (Exception ee)
                            {
                                errorMessage = "专题栏目栏目顶部图片更新数据库失败!" + ee.Message;
                            }

                        }
                    }
                    else
                    {
                        //判断是否是选择系统定义的模板
                        if (Fetch.Post("hidTopPicPath") != "")
                        {
                            try
                            {
                                string imgPath = Fetch.Post("hidTopPicPath");
                                string newImgPath = Url.Content("~/Publish/" + entityNo + "/DocClsLOGO/");
                                GenerateUtil.addfolder(newImgPath);
                                newImgPath += GenerateUtil.GenerateStringId() + imgPath.Substring(imgPath.LastIndexOf("."));
                                GenerateUtil.CopyFile( Url.Content("~" + imgPath), newImgPath);
                                docClsBLL.EditTopPicPath(newImgPath, entityNo, docClsCd);
                                //删除原来的图片(顶部图片)
                                if (!string.IsNullOrEmpty(docClsModel.FTemplTopPicPath))
                                {
                                    GenerateUtil.DeleteFile(Url.Content("~" + docClsModel.FTemplTopPicPath));
                                }
                            }
                            catch (Exception ee)
                            {
                                errorMessage = "专题栏目栏目顶部图片(系统定义的模板)更新数据库失败!" + ee.Message;
                            }
                        }
                    }
                }
                catch (Exception ee)
                {
                    errorMessage = "专题栏目栏目顶部图片上传出错" + ee.Message;
                }
            }
        }

        ///// <summary>
        ///// 上传图片
        ///// </summary>
        ///// <param name="strOldImgUrl"></param>
        ///// <param name="strDocClsCd"></param>
        ///// <param name="upload"></param>
        ///// <returns></returns>
        //public string ImageUpload(string imgUrl, string docClsCd, FileUpload upload)
        //{



        //    string strEntityNo = OperateSession.get("EntityNo");
        //    string strMsg = string.Empty;
        //    string strImageFileName = imgUpload.upload(upload, "~/Publish/" + strEntityNo + "/DocClsLOGO");

        //        string imageurl = "~/Publish/" + strEntityNo + "/DocClsLOGO/" + strImageFileName;

        //        if (upload.ID == "logoUpload")//logo的图片
        //        {
        //            if (editDocClsImg(imageurl, strEntityNo, strDocClsCd))
        //            {
        //                strMsg = "栏目logo图片更新数据库失败!";
        //            }
        //        }
        //        else if (upload.ID == "TemplTopPicPathUpload")//栏目顶部图片
        //        {
        //            BLL.docCls clsBll = new BLL.docCls();
        //            try
        //            {
        //                clsBll.editTopPicPath(imageurl, strEntityNo, strDocClsCd);
        //            }
        //            catch (Exception)
        //            {
        //                strMsg = "栏目顶部图片更新数据库失败";
        //            }
        //        }


        //        try
        //        {
        //            if (strOldImgUrl != string.Empty)//删除原来的图片
        //            {
        //                GenerateUtil.DeleteFile(strOldImgUrl);
        //            }
        //        }
        //        catch (Exception)
        //        {

        //        }



        //        return strMsg;
        //    }

        //    return strMsg;
        //}
        /// <summary>
        /// 生成权限权限指定部门,工作组,用户组,人
        /// </summary>
        /// <param name="ctlName">控件名称关键字</param>
        /// <param name="authorityType">权限类型</param>
        private void GenerateClsAuthorityList(string ctlName, string authorityType, string entityNo, ref List<Model.DocClsAuthority> docClsAuthorityList)
        {
            //发布权限
            if (Fetch.Post("chk" + ctlName + "QJ") == "C")
            {
                SetClsAuthorityList("", null, authorityType, "ALL", entityNo, ref docClsAuthorityList);
            }
            else
            {
                if (authorityType != "PUB")
                {
                    //发起部门
                    if (Fetch.Post("chk" + ctlName + "FQBM") == "C")
                    {
                        SetClsAuthorityList("cbo_" + authorityType + "_DEPT0_VI", null, authorityType, "DEPT0", entityNo, ref docClsAuthorityList);
                    }
                    //发起部门上级
                    if (Fetch.Post("chk" + ctlName + "FQBM_DEPT1") == "C")
                    {
                        SetClsAuthorityList("cbo_" + authorityType + "_DEPT1_VI", null, authorityType, "DEPT1", entityNo, ref docClsAuthorityList);
                    }
                    //发起部门上2级
                    if (Fetch.Post("chk" + ctlName + "FQBM_DEPT2") == "C")
                    {
                        SetClsAuthorityList("cbo_" + authorityType + "_DEPT2_VI", null, authorityType, "DEPT2", entityNo, ref docClsAuthorityList);
                    }
                    //发起部门上3级
                    if (Fetch.Post("chk" + ctlName + "FQBM_DEPT3") == "C")
                    {
                        SetClsAuthorityList("cbo_" + authorityType + "_DEPT3_VI", null, authorityType, "DEPT3", entityNo, ref docClsAuthorityList);
                    }
                    //发起部门上4级
                    if (Fetch.Post("chk" + ctlName + "FQBM_DEPT4") == "C")
                    {
                        SetClsAuthorityList("cbo_" + authorityType + "_DEPT4_VI", null, authorityType, "DEPT4", entityNo, ref docClsAuthorityList);
                    }
                    //发起部门上5级
                    if (Fetch.Post("chk" + ctlName + "FQBM_DEPT5") == "C")
                    {
                        SetClsAuthorityList("cbo_" + authorityType + "_DEPT5_VI", null, authorityType, "DEPT5", entityNo, ref docClsAuthorityList);
                    }
                    //发起部门上6级
                    if (Fetch.Post("chk" + ctlName + "FQBM_DEPT6") == "C")
                    {
                        SetClsAuthorityList("cbo_" + authorityType + "_DEPT6_VI", null, authorityType, "DEPT6", entityNo, ref docClsAuthorityList);
                    }
                    //分管领导
                    if (Fetch.Post("chk" + ctlName + "Charge") == "C")
                    {
                        SetClsAuthorityList("", null, authorityType, "CHARGE", entityNo, ref docClsAuthorityList);
                    }
                }
                string pubJson = "";
                //部门
                if (Fetch.Post("chk" + ctlName + "BM") == "C")
                {
                    pubJson = Fetch.Post("hdSel" + ctlName + "DeptKeys");
                    if (pubJson != "")
                    {
                        List<CommonValueModel> pubDetpObjList = JsonConvert.DeserializeObject<List<CommonValueModel>>(pubJson);
                        SetClsAuthorityList("cbo_" + ctlName + "Dept", pubDetpObjList, authorityType, "ASSIGNDEPT", entityNo, ref docClsAuthorityList);
                    }
                }
                if (Fetch.Post("chk" + ctlName + "GZZ") == "C")
                {
                    //工作组
                    pubJson = Fetch.Post("hdSel" + ctlName + "WorkGroupKeys");
                    if (pubJson != "")
                    {
                        List<CommonValueModel> pubDetpObjList = JsonConvert.DeserializeObject<List<CommonValueModel>>(pubJson);
                        SetClsAuthorityList("cbo_" + ctlName + "WrokGroup", pubDetpObjList, authorityType, "GROUP", entityNo, ref docClsAuthorityList);
                    }
                }
                if (Fetch.Post("chk" + ctlName + "GW") == "C")
                {
                    //岗位
                    pubJson = Fetch.Post("hdSel" + ctlName + "PositionKeys");
                    if (pubJson != "")
                    {
                        List<CommonValueModel> pubDetpObjList = JsonConvert.DeserializeObject<List<CommonValueModel>>(pubJson);
                        SetClsAuthorityList("", pubDetpObjList, authorityType, "POST", entityNo, ref docClsAuthorityList);
                    }
                }
                if (Fetch.Post("chk" + ctlName + "YHZ") == "C")
                {
                    //用户组
                    pubJson = Fetch.Post("hdSel" + ctlName + "GroupKeys");
                    if (pubJson != "")
                    {
                        List<CommonValueModel> pubDetpObjList = JsonConvert.DeserializeObject<List<CommonValueModel>>(pubJson);
                        SetClsAuthorityList("", pubDetpObjList, authorityType, "ROLE", entityNo, ref docClsAuthorityList);
                    }
                }
                //人员
                if (Fetch.Post("chk" + ctlName + "User") == "C")
                {
                    pubJson = Fetch.Post("hdSel" + ctlName + "UserKeys");
                    if (pubJson != "")
                    {
                        List<CommonValueModel> pubDetpObjList = JsonConvert.DeserializeObject<List<CommonValueModel>>(pubJson);
                        SetClsAuthorityList("", pubDetpObjList, authorityType, "PERSON", entityNo, ref docClsAuthorityList);
                    }
                }
            }
        }
        /// <summary>
        /// 删除信息类别
        /// </summary>
        /// <param name="docClsCd">信息类别编号</param>
        /// <returns>结果字符串 | 号分割</returns>
        [HttpPost]
        public string DeleteDocumentCls(string docClsCd)
        {
            string result = "FAILED";
            string errorMessage = "";
            string entityNo = GlobalConstant.ENTITYNO;
            if (docClsCd != "")
            {
                Model.DocCls docClsModel = docClsBLL.GetModel(entityNo, docClsCd);
                if (docClsModel != null)
                {
                    int childCount = docClsBLL.GetChildeCount(docClsCd, entityNo);
                    if (childCount == 0)
                    {
                        int documentCount = documentBLL.GetDocCountByDocClsCd(entityNo, docClsCd);

                        if (docClsModel.FDocClsProp == BaseStruct.DocClsTypeStruct.MUTI)
                        {
                            if (documentCount > 0)
                            {
                                errorMessage = "该多信息类别下存在信息数据,不能删除";
                            }
                        }
                        if (errorMessage == "")
                        {

                            string oldImgUrl = Fetch.Post("FLogoNewFileName");
                            List<string> listTemplate = sysTemplateBLL.GetFileNames(entityNo, docClsCd);//模板存放路径
                            bool isSingleDoc = false;
                            if (docClsModel.FDocClsProp == BaseStruct.DocClsTypeStruct.SINGLE && documentCount > 0)
                            {
                                //单信息且信息条数大于0
                                isSingleDoc = true;
                            }
                            docClsBLL.DeleteDocClsAndDocClsAuthority(entityNo, docClsCd, isSingleDoc);
                            try
                            {
                                if (oldImgUrl != string.Empty)
                                {
                                    GenerateUtil.DeleteFile(Url.Content("~" + oldImgUrl));
                                }
                                foreach (string str in listTemplate)
                                {
                                    GenerateUtil.DeleteFile(Url.Content("~" + str));
                                }
                                result = "SUCCESS";
                            }
                            catch (Exception ee)
                            {
                                errorMessage = "删除类别成功，但是删除相关文件失败" + ee.Message;
                            }
                        }
                    }
                    else
                    {
                        errorMessage = "该类别拥有子类别不能删除";
                    }
                }
                else
                {
                    errorMessage = "对应栏目不存在";
                }
            }
            if (result == "FAILED")
            {
                if (errorMessage == "")
                {
                    errorMessage = "错误";
                }
                result += "|" + errorMessage;
            }
            return result;
        }
        /// <summary>
        /// 信息类别是否存在
        /// </summary>
        /// <param name="docClsCd">信息类别编号</param>
        /// <returns>1-存在 0-不存在</returns>
        public string IsExistsDocClsCd(string docClsCd)
        {
            string result = "0";
            string entityNo = GlobalConstant.ENTITYNO;
            if (docClsBLL.Exists(entityNo, docClsCd))
            {
                result = "1";
            }
            return result;
        }
        /// <summary>
        /// 信息类别同级排序
        /// </summary>
        /// <param name="docClsCd">信息类别</param>
        /// <returns>视图</returns>
        public ActionResult DocumentClsSeq(string docClsCd)
        {
            string entityNo = GlobalConstant.ENTITYNO;
            Model.DocCls docClsModel = docClsBLL.GetModel(entityNo, docClsCd);
            ViewData["docListJson"] = "";
            ViewData["focusId"] = docClsCd;
            if (docClsModel != null)
            {
                List<Model.DocCls> docClsList = docClsBLL.GetListByEntityNoAndPreDocClsNo(entityNo, docClsModel.FPreDocClsCd);
                ViewData["docListJson"] = JsonConvert.SerializeObject(docClsList);
            }
            return View();
        }
        /// <summary>
        /// 排序保存
        /// </summary>
        /// <param name="docClsCds">排序的信息类别</param>
        /// <returns></returns>
        public string SaveRearrange(string docClsCds)
        {
            string result = "FAILED";
            string errorMessage = "";
            string entityNo = GlobalConstant.ENTITYNO;
            string[] docClsCdArray = docClsCds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            try
            {
                docClsBLL.SeqDocClsTop(docClsCdArray, entityNo);
                result = "SUCCESS";
            }
            catch (Exception ee)
            {
                errorMessage = "排序保存失败" + ee.Message;
            }


            if (result == "FAILED")
            {
                if (errorMessage == "")
                {
                    errorMessage = "错误";
                }
                result += "|" + errorMessage;
            }
            return result;
        }
        /// <summary>
        /// 设置权限
        /// </summary>
        /// <param name="ctlPropName">级别性质控件名称关键字</param>
        /// <param name="commonValueList">权限数据列表</param>
        /// <param name="authorityType">权限类型</param>
        /// <param name="pronoun">代词</param>
        /// <param name="sourceNo">对应编码</param>
        /// <param name="entityNo">公司编码</param>
        /// <param name="docClsAuthorityList">权限列表，引用</param>
        private void SetClsAuthorityList(string ctlPropName, List<CommonValueModel> commonValueList, string authorityType, string pronoun, string entityNo, ref List<Model.DocClsAuthority> docClsAuthorityList)
        {
            //发布权限
            if (commonValueList == null)
            {
                Model.DocClsAuthority docClsAuthorityModel = new Model.DocClsAuthority()
                {
                    FAuthorityType = authorityType,
                    FEntityNo = entityNo,
                    FPronoun = pronoun,
                    FProp = ctlPropName != "" ? Fetch.Post(ctlPropName) : "",
                    FSourceNo = ""
                };
                docClsAuthorityList.Add(docClsAuthorityModel);
            }
            else
            {
                foreach (CommonValueModel commValue in commonValueList)
                {
                    Model.DocClsAuthority docClsAuthorityModel = new Model.DocClsAuthority()
                    {
                        FAuthorityType = authorityType,
                        FEntityNo = entityNo,
                        FPronoun = pronoun,
                        FSourceNo = commValue.Value,
                        FProp = ctlPropName != "" ? Fetch.Post(ctlPropName + commValue.Value) : ""
                    };
                    docClsAuthorityList.Add(docClsAuthorityModel);
                }
            }
        }
        /// <summary>
        /// 当前栏目下的信息是否存在 控制到信息的 权限
        /// </summary>
        /// <param name="docClsCd">信息栏目种类</param>
        /// <returns></returns>
        public string ExistDocAuthority(string docClsCd)
        {
            string returnValue = "";
            try
            {
                if (documentAuthorityBLL.ExistByFDocClsCd(docClsCd))
                {
                    returnValue = "Exist";
                }
                else
                {
                    returnValue = "NotExist";
                }
            }
            catch (Exception ex)
            {
                returnValue = ex.ToString();
            }
            return returnValue;
        }
        /// <summary>
        /// 清除当前栏目的查看权限
        /// </summary>
        /// <param name="docClsCd">信息栏目种类</param>
        /// <returns></returns>
        public string ClearDocumentAuthority(string docClsCd)
        {
            string returnValue = "";
            try
            {
                documentAuthorityBLL.ClearDocAuthorityByFDocClsCd(docClsCd);
                returnValue = "SUCCESS";
            }
            catch (Exception ex)
            {
                returnValue = ex.ToString();
            }
            return returnValue;
        }

    }

}
